package cn.edu.cdtu.yulei.test_demo.service.impl;

import cn.edu.cdtu.yulei.test_demo.mapper.InterfaceMapper;
import cn.edu.cdtu.yulei.test_demo.model.InterfaceInfo;
import cn.edu.cdtu.yulei.test_demo.service.InterfaceInfoService;
import cn.edu.cdtu.yulei.test_demo.utils.SqlSessionUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class InterfaceInfoImpl implements InterfaceInfoService {

    /**
     * 获取接口信息
     * @return List<InterfaceInfo>
     */
    public List<InterfaceInfo> getInterfaceInfo(){
        SqlSession session = SqlSessionUtil.getSession();
        InterfaceMapper interfaceMapper = session.getMapper(InterfaceMapper.class);
        List<InterfaceInfo> interfaceInfos = interfaceMapper.getInterfaceInfo();
        session.close();
        return interfaceInfos;
    }

    /**
     * 修改接口访问数
     * @param url
     * @return int
     */
    public int addInterfaceInfo(String url){
        SqlSession session = SqlSessionUtil.getSession();
        InterfaceMapper interfaceMapper = session.getMapper(InterfaceMapper.class);
        int i = interfaceMapper.addViewNum(url);
        session.commit();
        session.close();
        return i;
    }
}
